<?php
namespace App\Services;
use App\Models\NewsModel;
use APP\Models\StoryColumnModel;
use App\Models\StoryTagModel;
use App\Models\StoryContentModel;

class StoryService{
	/**
	 * 插入文章
	 * @param array $data;
	 * @return bool $res;
	 */
	public function insertStory($data){
		$res = NewsModel::insert($data);
		return $res;
	}

	/**
	 * 获取文章列表
	 * @param string $status
	 * @return array $storylist
	 */
	public function getStoryList($status){
		$storylist = NewsModel::where('status',$status)->orderBy('story_date','desc')->take(10)->select('id','title','author','editor','story_date','edit_date','status')->get()->toArray();
		return $storylist;
	}

	/**
	 * 获取文章详细信息
	 * @param int $id
	 * @return array $storyInfo
	 */
	public function getStoryInfo($id){
		$storyInfo = NewsModel::where('id',$id)->first()->toArray();
		return $storyInfo;
	}

	/**
	 * 修改/删除文章
	 * @param int $id
	 * @param array $data
	 * @return bool $res
	 */
	public function updateStory($id,$data){
		$res = NewsModel::where('id',$id)->update($data);
		return $res;
	}
}